<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>拼团商品添加</title>
    <!--  <link href="../assets/css/layer.css"  />-->
    <link href="../assets/css/bootstrap.css" rel="stylesheet" />
    <link rel="stylesheet" href="../assets/css/bootstrapValidator.min.css" />
    <link rel="stylesheet" href="../assets/layui/layui-v2.5.4/css/layui.css"  media="all">
</head>
<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<style>
    th {
        text-align: center;
    }

    td {
        text-align: center;
    }

    tr {
        border: 1px solid #E6E6E6;
        line-height: 50px;
    }

    #tables{
        width: 100%;
    }

</style>
<body>

<div class="form-content">
    <br>
    <div class="layui-row">
        <div class="layui-col-xs12">
            <div class="layui-col-xs3 layui-col-xs-offset7" >
                       <input type="text" id="mh" name="title" value=""   placeholder="请输入搜索内容" autocomplete="off" class="layui-input">
                   </div>
                   <div class="layui-col-xs1">
                       <button id="mh_select" value="" style="height: 36px;margin-top: 1px;width: 60px" class="layui-btn layui-btn-normal layui-btn-sm" lay-event="mh_select">搜索</button>
                   </div>
            </div>
    </div>
    <hr />
    <div class="layui-row">
        <div class="layui-col-xs12">

            <table    cellspacing="0" id="tables">
               <!-- <tr>
                    <th width="30%">产品名称</th>
                    <th width="10%">商品价格</th>
                    <th width="30%">商品库存</th>
                    <th width="30%">操作/状态</th>
                </tr>-->
                <!--<tr>
                    <td>【奇异果】</td>
                    <td><input  type="text"  name="title" required  lay-verify="required"  autocomplete="off" class="layui-input"></td>
                    <td>【10】</td>
                    <td> <button  value="" style="height: 38px;width: 60px" class="layui-btn layui-btn-normal layui-btn-sm" lay-event="mh_select">上架</button></td>
                </tr>-->
            </table>
        </div>
    </div>
</div>

<script src="../assets/js/jquery-3.4.1.min.js"></script>
<script src="../assets/js/bootstrap.min.js"></script>
<script type="text/javascript" src="../assets/js/bootstrapValidator.min.js"></script>
<script src="../assets/layui/layui-v2.5.4/layui.js" charset="utf-8"></script>
<script src="../assets/js/layer.js"></script>
</body>

<script type="text/javascript">

    $(function () {
        queryWxGoodsStart();
    });

    var url=window.location.href;
    function queryWxGoodsStart(str) {
        $.ajax({
            type:"get",
            url:"/wxGoods/queryWxGoodsStart?goodsName="+str,
            success:function (result) {
              var   goods="";
              var   goodsTable='<tr>'+'<th width="30%">产品名称</th>'+'<th width="10%">商品价格</th>'+'<th width="30%">商品库存</th>'+'<th width="30%">操作/状态</th>'+'</tr>';
                $.each(result,function (i,v) {
                    if(v.start ==1){start = '上架'}else{start = '下架'};
                        goods+= '<tr>'+ '<td>【'+v.goods_name+'】</td>'+ '<td>【'+v.sales_price+'】</td>'+ '<td>【'+v.goods_num+'】</td>'+ '<td><button goodsId='+v.id+'  state='+v.start+' salesPrice='+v.sales_price+' name="bdGoods" value="" style="height: 38px;width: 60px" class="layui-btn layui-btn-normal layui-btn-sm  bdGoods" lay-event="bdGoods">'+start+'</button goodsId></td>'+ '</tr>'
                });
                $("#tables").html(goodsTable+goods);
                $(".bdGoods").on('click',function () {
                     var goodsId = $(this).attr("goodsId");
                     var spellId= url.substr(url.lastIndexOf("=")+1);
                   // var bt = $(this).parent().parent().children('.abobo').children().val();
                     var salesPrice=$(this).attr("salesPrice");
                     var state=0;
                    addWxSpellGoods(goodsId,spellId,salesPrice,state);
                });
            }
        });
    }

    function addWxSpellGoods(goodsId,spellId,salesPrice,state) {
        $.ajax({
            type:"post",
            url:"/wxSpellGoods/addWxSpellGoods",
            data:{spellId:spellId,goodsId:goodsId,spellPrice:salesPrice,spellGoodsState:state},
            success:function (result) {
            if(result>0)
            {
                parent.layer.msg('添加拼团商品成功！');
            }else{
                parent.layer.msg('该商品已与本次拼团绑定了哦！');
            }
            }
        });
    }

    $("#mh_select").on('click',function () {
        var  str =  $("#mh").val();
        queryWxGoodsStart(str);
    });

</script>
</html>
